package com.alander.nexusgo.framework.log.starter.service;

import com.alander.nexusgo.framework.log.starter.model.RequestLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class LogStatService {

    public void log(RequestLog logInfo) {
        if (logInfo.getException() != null) {
            log.error("[LogStat] 请求异常 | URI: {} | 异常: {}", logInfo.getUri(), logInfo.getException());
        } else {
            log.info("[LogStat] 请求完成 | URI: {} | 耗时: {}ms | 方法: {} | IP: {}",
                    logInfo.getUri(),
                    logInfo.getDuration(),
                    logInfo.getMethod(),
                    logInfo.getIp());
            if (logInfo.getParams() != null) {
                log.debug("[LogStat] 请求参数: {}", logInfo.getParams());
            }
            if (logInfo.getResult() != null) {
                log.debug("[LogStat] 响应结果: {}", logInfo.getResult());
            }
        }
    }
}
